package com.cqc.mebaidumapdemo;

import android.app.Activity;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;

import com.baidu.mapapi.SDKInitializer;
import com.baidu.mapapi.VersionInfo;
import com.cqc.mebaidumapdemo.activity.BaseMapDemo;
import com.cqc.mebaidumapdemo.activity.LocationMapDemo;
import com.cqc.mebaidumapdemo.adapter.MainAdapter;
import com.cqc.mebaidumapdemo.receiver.SDKReceiver;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * SDKReceiver
 * VersionInfo
 */
public class MainActivity extends AppCompatActivity implements AdapterView.OnItemClickListener {

    @BindView(R.id.tv1)
    TextView tv1;
    @BindView(R.id.listView)
    ListView listView;
    private SDKReceiver receiver;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        /**
         * 注册receiver
         */
        receiver = new SDKReceiver();
        IntentFilter filter = new IntentFilter();
        filter.addAction(SDKInitializer.SDK_BROADCAST_ACTION_STRING_NETWORK_ERROR);
        filter.addAction(SDKInitializer.SDK_BROADTCAST_ACTION_STRING_PERMISSION_CHECK_ERROR);
        filter.addAction(SDKInitializer.SDK_BROADTCAST_ACTION_STRING_PERMISSION_CHECK_OK);
        filter.addAction(SDKInitializer.SDK_BROADTCAST_INTENT_EXTRA_INFO_KEY_ERROR_CODE);
        registerReceiver(receiver, filter);

        tv1.setText("sdk版本：" + VersionInfo.getKitName());
        MainAdapter adapter = new MainAdapter(this);
        listView.setAdapter(adapter);
        listView.setOnItemClickListener(this);

    }

    @Override
    protected void onDestroy() {
        unregisterReceiver(receiver);
        super.onDestroy();
    }


    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
        Intent intent = null;
        switch (i) {
            case 0:
                intent = new Intent(MainActivity.this, BaseMapDemo.class);
                break;
            case 1:
                break;
            case 2:
                break;
            case 3:
                break;
            case 4:
                break;
            case 5:
                break;
            case 6:
                intent = new Intent(MainActivity.this, LocationMapDemo.class);
                break;
            case 7:
                break;
        }
        startActivity(intent);
    }
}
